home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / amos / intuiextend16.lha / bonus / easylife / demos / Shorten.AMOS / Shorten.amosSourceCode
AMOS Source Code  |  1992-02-26  |  6KB  |  158 lines

  1. '****************************************************************************
  2. '**      Program Shortener V1.0  -  By Paul Hickman (ph@doc.ic.ac.uk)      **
  3. '**                                                                        **
  4. '**  Requires AMOS Pro & Easylife V1.4+   Distributed as an Eastlife Demo  **
  5. '**                                                                        **
  6. '**  Do not use this accessory on programs which contain procedures that   **
  7. '**  not be unfolded, if they have variable names in the parameters of 2   **
  8. '**  characters or more!                                                   **
  9. '****************************************************************************
  10.  
  11. Set Accessory 
  12. Set Buffer 50
  13. Dim TB$(30)
  14. Global AL$,WHITE$,TB$(),NNAME,QUOTE$
  15. For A=0 To 30 : TB$(A)="|" : Next 
  16. WHITE$=Chr$(32)+Chr$(9) : SCY=60 : NNAME=0 : FOLD$="" : LABEL$="|"
  17. QUOTE$=Chr$(34)+Chr$(39)
  18. NAST$=QUOTE$+"ABCDEFGHIJKLMNOPQSTRUVWXYZ_"
  19. INIT_SCREEN
  20.  
  21. ' Make sure we are an accessory
  22. If Prg Under<>1
  23.    If Exist("Shorten.Doc")
  24.       Read Text "Shorten.Doc"
  25.    Else 
  26.       NULL=Dialog Box(AL$,1,"This program must be run as an accessory!")
  27.    End If 
  28.    MN_QUIT
  29. End If 
  30.  
  31. DLOG2["Shorten Variable Names, Or Just Strip Comments","Comments","Variables"] : SHORT=(Param=2)
  32. If SHORT
  33.    SCAN_FOLDED
  34.    If Param
  35.       DLOG2["Program contains calulcated branches. Labels will not be shortened","Continue","Abort"]
  36.       If Param=2 : MN_QUIT : End If 
  37.    End If 
  38. End If 
  39.  
  40. COMMENT_STRIP[SHORT]
  41. MN_QUIT
  42.  
  43.  
  44. Procedure SHORTEN
  45.    Shared LINE$,NAST$
  46.    
  47.  
  48.  
  49.    CHANGE=False
  50.    
  51.    A= Extension_16_00AA(LINE$,NAST$)
  52.    While A>0
  53.       B=Peek(Varptr(LINE$)+A-1)
  54.       If(B=39) or(B=34)
  55.          C= Extension_16_009E(LINE$,B,A)
  56.          Exit If C=0
  57.          A=C
  58.       Else 
  59.          C=Peek(Varptr(LINE$)+A)
  60.          If((C>64) and(C<91)) or((C>47) and(C<58)) or(C=95)
  61.             'Looks Like A Legal Label - Check Quotes & Hex String
  62.             
  63.             NHEX=True
  64.             DL= Extension_16_0122(LINE$,36,A)
  65.             If DL>0
  66.                NHEX=( Extension_16_00EA(Mid$(LINE$,DL+1,A-DL),"0123456789ABCDEF")>0)
  67.             End If 
  68.             
  69.             If NHEX
  70.                C= Extension_16_0100(LINE$,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_",A)
  71.                If C=0
  72.                   N$=Mid$(LINE$,A)
  73.                Else 
  74.                   N$=Mid$(LINE$,A,C-A)
  75.                End If 
  76.                SHORT_LOOKUP[N$] : L$=Param$
  77.                If L$=""
  78.                   Add A,Len(N$)
  79.                Else 
  80.                   LINE$=Left$(LINE$,A-1)+L$+Mid$(LINE$,A+Len(N$))
  81.                   Add A,Len(L$)
  82.                   CHANGE=True
  83.                End If 
  84.             End If 
  85.             
  86.          Else 
  87.             'Not a label - check for a zero, -1 or 4 
  88.             '         If(L<250) and(A>0) 
  89.             '            C=Peek(Varptr(LINE$)+A-1) 
  90.             '            If Elf asc(" ,=<>(*+/[",C)>0  
  91.             '               If(B=48) or(B=52)
  92.             '                  C=Peek(Varptr(LINE$)+A+1) 
  93.             '                  If((C<48) or(C>57)) and(C<>46)
  94.             '                     QUOTE_CHECK[Left$(LINE$,A+1)]
  95.             '                     If Param=False 
  96.             '                        AA$="False" : If B=52 : AA$="Laced" : End If  
  97.             '                        LINE$=Left$(LINE$,A)+AA$+Mid$(LINE$,A+2)
  98.             '                     End If 
  99.             '                  End If  
  100.             '               End If 
  101.             '            End If  
  102.             '         End If 
  103.          End If 
  104.       End If 
  105.       A= Extension_16_00BC(LINE$,NAST$,A)
  106.  
  107.    Wend 
  108. End Proc[CHANGE]
  109. Procedure SHORT_LOOKUP[A$]
  110.    Shared LABEL$
  111.    X=Asc(A$)-65
  112.    If(X<0) or(X>30)
  113.       Error 23
  114.    End If 
  115.    NO=Instr(LABEL$,"|"+A$+"|")
  116.    If NO
  117.       B$=""
  118.    Else 
  119.       A=Instr(TB$(X),"|"+A$+"|")
  120.       If A>0
  121.          B$=Upper$(Mid$(TB$(X),A+Len(A$)+2,Instr(TB$(X),"|",A+Len(A$)+2)-A-Len(A$)-2))
  122.       Else 
  123.          '1st Character Of Label = letter NNAME mod 25          
  124.          '2nd Character Of Label = number nname/25 mod 10 (Prevents labels matching instructions like At) 
  125.          '3rd Character Of Label (if Present) = letter NNAME / 250
  126.          '
  127.          Repeat 
  128.             B$=Chr$(NNAME mod 25+65)+Chr$((NNAME/25) mod 10+48)
  129.             If NNAME=>250
  130.                B$=B$+Chr$(NNAME/250+65)
  131.             End If 
  132.             Inc NNAME
  133.          Until Instr(LABEL$,"|"+B$+"|")=0
  134.          TB$(X)=TB$(X)+A$+"|"+Lower$(B$)+"|"
  135.       End If 
  136.    End If 
  137.    
  138. End Proc[B$]
  139. Procedure COMMENT_STRIP[SHORT]
  140.    Shared LINE$,FOLD$
  141.    TITLE
  142.    Clear Key : Y=0 : DELD=0
  143.    Call Editor 89 : Rem Equ("AEd_UnfoldAll") 
  144.    Call Editor 17 : Rem Top Of Text  
  145.    Ask Editor 5 : NLINES=Param : NFOLD=0
  146.    Repeat 
  147.       DELETE=False
  148.       Ask Editor 1 : LINE$=Param$
  149.       'Search for ' at start of line   
  150.       B= Extension_16_00EA(LINE$,WHITE$) : A=Asc(Mid$(LINE$,B))
  151.       If(A=39) or(B=0)
  152.          Call Editor 23 : Rem Delete Line
  153.          Dec NLINES : Inc DELD
  154.          DELETE=True
  155.       Else 
  156.          '
  157.          'Search For: ,_������gtNup^�� Extension_0_FFFF 
  158.                                                                                                                                                                                                                                                                Extension_0_6704 Extension_0_7402 Extension_0_4E75 Extension_0_705E Extension_0_FE01 Extension_0_F700 Extension_0_0400 Extension_0_2708 Extension_0_206D Extension_0_01E8 Extension_0_2028 Extension_0_00FC Extension_0_661E Extension_0_48E7 Extension_0_00C2 Extension_0_43FA Illegal_Constant_0022 Extension_0_7005 Extension_0_2C78 L�C Extension_0_4E75 Extension_0_FE31 "| Extension_0_0075 Extension_0_FE31 0�'@��R